﻿@{
    Layout = "~/Views/Shared/_ManageLayoutPage.cshtml";
}
@model TBlog.Web.Common.PageHelper.PagedList<TBlog.Web.Models.Category>
<blockquote class="layui-elem-quote">
    <a href="@Url.Action("Create", "Category")" class="layui-btn"><i class="layui-icon">&#xe61f;</i> 创建分类</a>

</blockquote>
<div class="layui-form">
    <table class="layui-table">
        <colgroup>
            <col width="50" />
            <col width="150" />
            <col width="150" />
            <col width="200" />
        </colgroup>
        <thead>
            <tr>
                <th>
                    <input type="checkbox" name="" id="" lay-skin="parimary" lay-filter="allChoose" />
                </th>
                <th>分类名称</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @if (Model.Items != null && Model.Items.Count > 0)
            {
                foreach (var item in Model.Items)
                {
                <tr>
                    <td>
                        <input type="checkbox" name="" lay-skin="parimary" value="@item.ID" /></td>
                    <td>@item.CategoryName</td>
                    <td>@item.CreateTime.ToString("yyyy年MM月dd日 hh:mm:ss")</td>
                    @*    <td> <a href="@Url.Action("Edit", "Category", new { id = item.ID })">编辑</a>
                        <a href="javascript:;" data-id="@item.ID" data-options="del" data-name="@item.CategoryName">删除</a>
                    </td>*@
                    <td>
                        <a href="@Url.Action("Edit", "Category", new { id = item.ID })">
                            <i class="layui-icon" style="font-size: 15px; color: #1E9FFF;">&#xe642;</i>  编辑</a>
                        <a href="javascript:;" data-id="@item.ID" data-opentions="del" data-name="@item.CategoryName"><i class="layui-icon" style="font-size: 15px; color: #1E9FFF;">&#xe640;</i>  删除</a></td>

                </tr>
                }
            }
            else
            {
                <tr>
                    <td> 没有数据<i class="layui-icon" style="font-size: 30px; color: #1E9FFF;">&#xe60c;</i></td>
                </tr>
            }
        </tbody>
    </table>
</div>
@section scripts{
    <script>
        layui.use(['layer','form'], function () {
            var layer = layui.layer
            , $ = layui.jquery
            ,form=layui.form();
            form.on('checkbox(allChoose)', function (data) {
                var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
                child.each(function (index, elem) {
                    elem.checked = data.elem.checked;
                });
                form.render('checkbox');
            })
            $('a[data-options=del]').each(function () {
                var $this = $(this);

                $this.on('click', function () {
                    var id = $this.data('id');
                    var name = $this.data('name');
                    var msg = '你真的要把  <span style="color:red;">' + name + '</span> 给删除吗？<img src="' + location.origin + '/Lay/images/face/4.gif" alt="[可怜]">'
                    var title = '萌萌的提示<img src="' + location.origin + '/Lay/images/face/7.gif" alt="[害羞]">'
                    layer.confirm(msg, { icon: 3, title: title }, function (index) {
                        var params = {
                            t: Math.random(),
                            id: id
                        };
                        $.post('@Url.Action("Delete", "Category")', params, function (result) {

                            if (result.success) {
                                layer.msg(result.message, { icon: 1 }, function (index) {
                                    location.reload();
                                });
                            }
                            else {
                                layer.msg(result.message, { icon: 2 });
                            }

                        }, 'json');
                        layer.close(index);
                    });
                });
            });
            var $item = $('.layui-nav > .layui-nav-item');
            $item.removeClass('layui-this').eq(3).addClass('layui-this');


        });

    </script>
}
